package com.yonder.controller;

import com.yonder.common.MessageConstant;
import com.yonder.entity.Result;
import com.yonder.pojo.CheckGroup;
import com.yonder.service.CheckGroupService;
import com.yonder.service.CheckItemsService;
import org.apache.ibatis.executor.ReuseExecutor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName CheckGroupController
 * @Description TODO
 * @Author zxs
 * @Date 2021/3/20 19:34
 * Version 1.0
 */

@RestController
@RequestMapping("/checkgroup")
public class CheckGroupController {

    @Autowired
    private CheckGroupService checkGroupService;
    /*
    * 添加检查组
    * */
    @RequestMapping("/add")
    public Result add( @RequestBody CheckGroup checkGroup,Integer[] checkitemIds){
        try {
            checkGroupService.add(checkGroup,checkitemIds);
            return new Result(false, MessageConstant.ADD_CHECKGROUP_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Result(false, MessageConstant.ADD_CHECKGROUP_FAIL);
    }

    /*
    * 删除检查组
    * */
    @RequestMapping("/deleteGroup")
    public Result deleteGroup( Integer checkGroupId){
        checkGroupService.deleteGroup(checkGroupId);
        return new Result(false,MessageConstant.DELETE_CHECKGROUP_FAIL);
    }

    /*
    * 查询检查组数据
    * */
    @RequestMapping("findAll")
    public Result findAllGroup(){
        try {
            List<CheckGroup> list = checkGroupService.findAllGroup();
            return new Result(true,MessageConstant.QUERY_CHECKGROUP_SUCCESS,list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  new Result(true,MessageConstant.QUERY_CHECKGROUP_FAIL);
    }
}
